﻿using System.IO;
using JetBlack.IO;

namespace JetBlack.TopicBus.Messages
{
    internal class NotificationRequest : Message
    {
        public readonly bool IsAdd;
        public readonly string TopicPattern;

        public NotificationRequest(string topicPattern, bool isAdd)
            : base(MessageType.NotificationRequest)
        {
            TopicPattern = topicPattern;
            IsAdd = isAdd;
        }

        new static public NotificationRequest Read(Stream reader)
        {
            string topicPattern = reader.ReadString();
            bool isAdd = reader.ReadBoolean();
            return new NotificationRequest(topicPattern, isAdd);
        }

        public override Stream Write(Stream writer)
        {
            base.Write(writer);
            writer.Write(TopicPattern);
            writer.Write(IsAdd);
            return writer;
        }

        override public string ToString()
        {
            return string.Format("{0} {1} {2}", MessageType, TopicPattern, IsAdd);
        }
    }
}
